using System;
using System.Windows.Forms;

using FreeFlow.Administration;

namespace FreeFlowAdministrator
{
	/// <summary>
	/// Summary description for UsersAdaptor.
	/// </summary>
	public class UsersAdaptor : Adaptor, IRefreshable
	{
    private UserCollection users;
		public UsersAdaptor(UserCollection users)
		{
      this.users = users;
		}

    public override void AddChildren(System.Windows.Forms.TreeNode node)
    {
      foreach (User user in users)
      {
        TreeNode childNode = TreeNodeFactory.CreateTreeNode(new UserAdaptor(user));
        node.Nodes.Add(childNode);
      }
    }

    public override int ImageIndex
    {
      get
      {
        return 5;
      }
    }

    public override string Text
    {
      get
      {
        return "Users (" + users.Count + ")";
      }
    }

    public override Control GetRenderer()
    {
      UsersControl control = new UsersControl();
      control.LoadUsers(users);
      control.UserAdded += new EventHandler(TriggerItemAdded);
      control.RefreshRequired += new EventHandler(TriggerRefreshRequired);
      return control; 
    }

    public override object Object
    {
      get
      {
        return users;
      }
    }

    #region IRefreshable Members

    public void Refresh()
    {
      users.Refresh();
    }

    #endregion
  }
}
